import os

class ReFileName(object):
    def reFileName(self, filepath, oldRule, newRule):
        '''
        批量改名
        :param filepath:需要更改名称的文件路径 
        :param oldRule: 旧字段
        :param newRule: 新字段
        :return: 
        '''
        for (path, dirs, files) in os.walk(filepath):
            for filename in files:
                # print(filename)
                if (oldRule in str(filename)):
                    newname = str(filename).replace(oldRule, newRule)
                    print(path + "\\" + newname)
                    os.rename(path + "\\" + filename, path + "\\" + newname)
                else:
                    print("no rename " + path + "\\" + filename)

if __name__=='__main__':
    path = "G:\GetFile\icon\iconnew"
    ReFileName().reFileName(path, '-', '_')